// 导入axios工具包，这个模块封装首页模块的所有ajax请求
import instance from '@/utils/axios.js'

// 获取频道列表
const getChannels = () => {
  return instance({
    url: '/v1_0/channels',
    method: 'get'
  })
}
// 导出接口
export {
  getChannels
}

const getArticles = ({
  channel_id,
  timestamp
}) => {
  return instance({
    url: '/v1_0/articles',
    method: 'get',
    params: {
      with_top: 1,
      channel_id,
      timestamp
    }
  })
}
// 导出接口
export {
  getArticles
}

// 3.文章详细信息
function getArticleInfo(id) {
  return instance({
    url: `/v1_0/articles/${id}`,
    method: 'get'
  })
}
// 导出接口
export {
  getArticleInfo
}

// 4.关注接口
// 4.1关注
const followUser = ({
  target
}) => {
  return instance({
    url: '/v1_0/user/followings',
    method: 'post',
    data: {
      target
    }
  })
}

//4.2取消用户
const unFollowUser = ({
  target
}) => {
  return instance({
    //这个接口的id直接在路径后面拼接  格式： url/target
    url: '/v1_0/user/followings/' + target,
    method: 'delete',
  })
}
//导出接口
export {
  followUser,
  unFollowUser
}
/* 6.点赞与取消点赞 */

//点赞
const addPraise = id => {
  return instance({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

//取消点赞
const cancelPraise = id => {
  return instance({
    method: 'delete',
    //这个接口的id直接在路径后面拼接  格式： url/target
    url: '/v1_0/article/likings/' + id
  })
}

//导出接口
export {
  addPraise,
  cancelPraise
}
/* 7.不喜欢与取消不喜欢 */

//不喜欢
const addDisLike = id => {
  return instance({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

//取消不喜欢
const cancelDisLike = id => {
  return instance({
    method: 'delete',
    //这个接口的id直接在路径后面拼接  格式： url/target
    url: '/v1_0/article/dislikes/' + id
  })
}

//导出接口
export {
  addDisLike,
  cancelDisLike
}

// 搜索推荐词列表
function getSuggestion(q) {
  return instance({
    url: '/v1_0/suggestion',
    method: 'get',
    params: {
      q
    }
  })
}
export {
  getSuggestion
}

// 搜索结果列表
function getSearchList({
  page,
  q
}) {
  return instance({
    url: '/v1_0/search',
    method: 'get',
    params: {
      per_page: 10,
      page,
      q
    }
  })
}
export {
  getSearchList
}
